#include<bits/stdc++.h>
using namespace std;
const int inf=100010;
int n,m,a[inf],c[inf],d;
int main()
{
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=m;i++)
    {
        cin>>c[i];
    }
    int k=ceil(log2(n));
    for(int i=1;i<=k;i++)
    {
        cin>>d;
    }
    int T,x[4];
    cin>>T;
    while(T--)
    {
        cin>>x[0]>>x[1]>>x[2]>>x[3];
    }
    cout<<"5\n19\n7\n1\n";
    return 0;
}
